<template>
  <el-config-provider :locale="elementLocale">
    <router-view/>
  </el-config-provider>
</template>
<script setup>
import { onMounted, computed } from 'vue';
import { useI18n } from 'vue-i18n';
import { useThemeStore } from '@/stores/theme';
import { useLocaleStore } from '@/stores/locale';
// Element Plus 语言包
import zhCN from 'element-plus/es/locale/lang/zh-cn';
import enUS from 'element-plus/es/locale/lang/en';
import jaJP from 'element-plus/es/locale/lang/ja';

const themeStore = useThemeStore();
const localeStore = useLocaleStore();
const { locale } = useI18n();

// Element Plus 语言包映射
const elementLocaleMap = {
  'zh-CN': zhCN,
  'en-US': enUS,
  'ja-JP': jaJP
};

// 动态切换 Element Plus 语言
const elementLocale = computed(() => {
  return elementLocaleMap[localeStore.currentLocale] || zhCN;
});

// 同步 i18n locale 和 localeStore
const syncLocale = () => {
  locale.value = localeStore.currentLocale;
};

onMounted(() => {
  // 初始化主题
  themeStore.initTheme();
  
  // 初始化语言
  localeStore.initLocale();
  syncLocale();
  
  // 移除加载页面
  const loadingElement = document.getElementById('loadingPage');
  if (loadingElement) {
    loadingElement.remove();
  }
});
</script>
<style lang="less"></style>
